package day11;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author oldliu
 * @since 1.0
 */
public class INvokeClass {
    public static void main(String[] args) throws Exception {
        //调用
        //调用私有的
        Class<Bank> bankClass = Bank.class;
        Bank bank = bankClass.newInstance();//只能调用无参的构造
        System.out.println(bank);
        Constructor<Bank> constructor = bankClass.getDeclaredConstructor(String.class, String.class, float.class);
        constructor.setAccessible(true);//!!!摆脱私有的限制
        Bank bank2 = constructor.newInstance("chenyi---1", "陈奕", 555.4F);
        System.out.println(bank2);
        //私有的属性
        Field city = bankClass.getDeclaredField("city");
        city.setAccessible(true);
        city.set(bank2,"合肥");//必须有个对象 obj.name="laoisss"
        System.out.println(bank2);
        //私有方法
        Method m1 = bankClass.getDeclaredMethod("setCardAndMoney", String.class, float.class);
        m1.setAccessible(true);
        Object rtn=m1.invoke(bank2,"a0000001",366666.5F);
        System.out.println(m1.getName()+"方法返回了"+rtn);
        System.out.println(bank2);
    }

}
